package rpc.client;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import rpc.client.socket.MinaClientSocket;

public class ClientStart {
    
    private static ThreadPoolExecutor threadPoolSocket = new ThreadPoolExecutor(4, 8, 3, TimeUnit.SECONDS,
            new ArrayBlockingQueue<Runnable>(500), new ThreadPoolExecutor.CallerRunsPolicy());
    
    static {
        try {
            //Class.forName("rpc.client.socket.ClientSocket", true, Thread.currentThread().getContextClassLoader());
            Class.forName("rpc.client.socket.MinaClientSocket", true, Thread.currentThread().getContextClassLoader());
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        List<String> strList = new ArrayList<>();
        strList.add("request1");
        /*strList.add("request2");
        strList.add("request3");
        strList.add("request4");
        strList.add("request5");*/
        for (String request : strList) {
            threadPoolSocket.execute(new Runnable() {
                @Override
                public void run() {
                    //Object response = ClientSocket.oneRpcSericeMethodRun(request);
                    //System.out.println("result is:"+response.toString());
                    MinaClientSocket.sendMsg2Server(request);
                }
            });
        }
    }

}
